package com.example.testrecorder.utils;

import android.app.Activity;
import android.os.Process;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Yingyong Lao
 * 创建时间 2021/5/16 19:38
 * @version 1.0
 */
public class ActivityCollector {
    private static ActivityCollector activityCollector;
    private List<Activity> list=new ArrayList<>();
    private ActivityCollector(){};
    public static ActivityCollector getInstance(){
        if (activityCollector==null){
            activityCollector=new ActivityCollector();
        }
        return activityCollector;
    }
    public void addOne(Activity activity){
        list.add(activity);
    }
    public void removeOne(Activity activity){
        list.remove(activity);
    }
    public  void removeAll(){
        for (Activity activity : list) {
            if(!activity.isFinishing()){
                activity.finish();
            }
        }
        list.removeAll(list);
        //Process.killProcess(Process.myPid());//杀掉当前进程
    }
}
